package com.example.qqviewspringboot.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import javax.annotation.PostConstruct;
import java.io.IOException;
import java.nio.file.*;

@Configuration
public class UploadConfig {

    @Value("${avatar.storage.path}")
    private String avatarStoragePath;

    @Value("${media.storage.path}")
    private String mediaStoragePath;

    @PostConstruct
    public void init() {
        try {
            Path avatarPath = Paths.get(avatarStoragePath);
            if (!Files.exists(avatarPath)) {
                Files.createDirectories(avatarPath);
            }

            Path mediaPath = Paths.get(mediaStoragePath);
            if (!Files.exists(mediaPath)) {
                Files.createDirectories(mediaPath);
            }
        } catch (IOException e) {
            e.printStackTrace();
            throw new RuntimeException("Could not create upload directories!");
        }
    }
}
